package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* ClassName: UserMapper
* Package: com.qk.mapper
* Description: 
* @Author zt
* @Create 2025/7/28 17:14 
* @Version 1.0
*/
@Mapper
public interface UserMapper {

    /*
    分页查询用户
     */
    List<User> selectByCondition(UserDto userDto);

    /*
    添加用户
     */
    @Insert("insert into user(username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time) " +
            "values(#{username}, #{password}, #{name}, #{phone}, #{email}, #{gender}, #{status}, #{deptId}, #{roleId}, " +
            "#{image}, #{remark}, #{createTime}, #{updateTime})")
    void add(User user);

    /*
    批量删除用户
     */
    void delete(List<Integer> ids);

    /*
    根据ID查询用户
     */
    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, " +
            "image, remark, create_time, update_time from user where id = #{id}")
    User getById(Integer id);

    /*
    更新用户
     */
    void update(User user);

    /*
    查询所有用户
     */
    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, " +
            "image, remark, create_time, update_time from user")
    List<User> list();

    List<User> listByRole(String roleLabel);

    List<User> listByDept(Integer deptId);

    @Select("select u.*, r.label role_label from user u left join role r on u.role_id = r.id where username = #{username}")
    User selectByUsername(String username);
}
